class KthLargest {
public:
    priority_queue<int,vector<int>,greater<int>> p;
    int _k;

    KthLargest(int k, vector<int>& nums) {
        _k=k;
        for(auto& ch:nums)
        {
            p.push(ch);
            while(p.size()>k) p.pop();
        }
    }
    
    int add(int val) {
        p.push(val);
        while(p.size()>_k) p.pop();
        return p.top();    
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */
